package com.tiancheng.onecode.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tiancheng.onecode.entity.User;
import com.tiancheng.onecode.model.request.admin.MerchantQueryReq;
import com.tiancheng.onecode.model.request.admin.MerchantUserQueryReq;
import com.tiancheng.onecode.model.request.admin.PlatformMerchantUserAddReq;
import com.tiancheng.onecode.model.response.PageInfo;
import com.tiancheng.onecode.model.response.Result;
import com.tiancheng.onecode.model.response.admin.MerchantUserQueryRes;
import com.tiancheng.onecode.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: kellen
 * @Description: B端用户admin controller
 * @Date: create in 2024/12/12 16:47
 */
@Controller
@RequestMapping("/admin/user")
public class UserAdminController {

    @Resource
    private IUserService userService;

    /**
     * 根据电话查询管理员
     *
     * @param phone
     * @return
     */
    @GetMapping(value = "/queryByPhone")
    @ResponseBody
    public Result<List<User>> queryPage(@RequestParam("phone") String phone) {
        List<User> users = userService.list(new LambdaQueryWrapper<User>().eq(User::getPhone, phone));
        return Result.success(users);
    }

    /**
     * 管理员列表
     *
     * @param params
     * @return
     */
    @GetMapping(value = "/queryPage")
    @ResponseBody
    public Result<PageInfo<MerchantUserQueryRes>> queryPage(MerchantUserQueryReq params) {
        final PageInfo<MerchantUserQueryRes> page = userService.queryPage(params);
        return Result.success(page);
    }

    /**
     * 添加管理员
     *
     * @param params
     * @return
     */
    @PostMapping(value = "/add")
    @ResponseBody
    public Result addMerchantUser(@RequestBody PlatformMerchantUserAddReq params) {
        userService.addMerchantUser(params);
        return Result.success();
    }

    /**
     * 管理员明细信息
     *
     * @param platformMerchantUserId
     * @return
     */
    @GetMapping(value = "/detail")
    @ResponseBody
    public Result<MerchantUserQueryRes> detail(@RequestParam("platformMerchantUserId") Long platformMerchantUserId) {
        MerchantUserQueryRes res = userService.detail(platformMerchantUserId);
        return Result.success(res);
    }

    /**
     * 查询当前商户超级管理员
     *
     * @param platformMerchantId 平台商户id
     * @return
     */
    @GetMapping(value = "/queryMerchantSuperAdmin")
    @ResponseBody
    public Result<MerchantUserQueryRes> queryMerchantSuperAdmin(@RequestParam("platformMerchantId") Long platformMerchantId) {
        MerchantUserQueryRes res = userService.queryPlatformMerchantId(platformMerchantId);
        return Result.success(res);
    }
}
